﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Xml.Serialization;

namespace UML_Creator.Model
{
    [Serializable]
    [XmlRoot(Namespace = "UML stuff")]
    [XmlInclude(typeof(ClassDiagram))]
    public class Diagram : NotifyBase
    {

        public string Title { get; set; }
        public string Description { get; set; }
        public int ID { get; set; }

        // Properties. Normalt ville automatiske attributter benyttes, som svarer til at lave et privat felt (fx x), 
        // og offentlige get og set metoder (fx GetX() og SetX()) i Java. 
        // Fx: public int X { get; set; }
        // Men på grund af at NotifyPropertyChanged skal smides i setter metoden må vi her benytte os af almindelige attributer og get/set metoder.
        // Get / set metoderne er dog stadig meget anderledes end i Java hvor man ville have en GetX() og SetX() metode.
        private static int counter = 0;
        public int Number { get; set; }
        private int x;
        public int X { get { return x; } set { x = value; NotifyPropertyChanged("X"); NotifyPropertyChanged("CanvasCenterX"); } }
        private int y;
        public int Y { get { return y; } set { y = value; NotifyPropertyChanged("Y"); NotifyPropertyChanged("CanvasCenterY"); } }
        private int width;
        public int Width { get { return width; } set { width = value; NotifyPropertyChanged("Width"); NotifyPropertyChanged("CenterX"); NotifyPropertyChanged("CanvasCenterX"); } }
        private int height;
        public int Height { get { return height; } set { height = value; NotifyPropertyChanged("Height"); NotifyPropertyChanged("CenterY"); NotifyPropertyChanged("CanvasCenterY"); } }

        // Derived properties. Svarer til at lave en get metode i Java (fx GetCenterX()) som ikke har sit eget bagvedliggende felt.
        public int CanvasCenterX { get { return X + width / 2; } set { X = value - width / 2; NotifyPropertyChanged("X"); } }
        public int CanvasCenterY { get { return Y + height / 2; } set { Y = value - height / 2; NotifyPropertyChanged("Y"); } }
        public int CenterX { get { return width / 2; } }
        public int CenterY { get { return height / 2; } }

        private string colour;
        public string Colour { get { return colour; } set { colour = value; NotifyPropertyChanged("Colour"); } }

        private double opacity;
        public double Opacity { get { return opacity; } set { opacity = value; NotifyPropertyChanged("Opacity"); } }

        // ViewModel properties. Den burde være i sin egen ViewModel klasse som Node klasserne wrappes af, men i dette tilfælde er det her meget lettere.
        private bool isSelected;
        public bool IsSelected { get { return isSelected; } set { isSelected = value; NotifyPropertyChanged("IsSelected"); NotifyPropertyChanged("SelectedColor"); } }
        public Brush SelectedColor { get { return IsSelected ? Brushes.Red : Brushes.Yellow; } }

        public Diagram()
        {
            ID = this.GetHashCode();
            Number = ++counter;
            width = height = 100; //TODO: This is fucking bad
            Colour = "Black";
            Opacity = 1.0;
        }
    }
}
